/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crm.salesOrderProcessing.managedbean;

import commonInfrastructure.accountManagement.entity.EmployeeEntity;
import commonInfrastructure.accountManagement.entity.SalesmanEntity;
import commonInfrastructure.accountManagement.session.SalesmanSessionBean;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import crm.salesOrderProcessing.entity.SalesOrderEntity;
import crm.salesOrderProcessing.session.SalesOrderSessionBean;
import crm.salesOrderProcessing.util.exception.NoPurchaseOrderException;

/**
 *
 * @author xhx
 */
@ManagedBean
@ViewScoped
public class ViewAllPurchaseOrderManagedBean {

    private SalesOrderEntity selectedPurchaseOrder;
    private SalesmanEntity employee;
    private Boolean renderFlag;
    @EJB
    SalesOrderSessionBean salesOrderSessionBean;
    @EJB
    SalesmanSessionBean employeeManager;

    /** Creates a new instance of ViewAllSalesOrderManagedBean */
    public ViewAllPurchaseOrderManagedBean() {
        selectedPurchaseOrder = new SalesOrderEntity();
    }

    public List<SalesOrderEntity> getPurchaseOrderList() throws IOException {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Long userId = (Long) request.getSession().getAttribute("userId");
        employee = employeeManager.getSalesmanById(userId);
        List<SalesOrderEntity> result = new ArrayList();

     
        return result;
    }
    public void viewPurchaseOrder(SalesOrderEntity salesOrder) throws IOException {
        selectedPurchaseOrder = salesOrder;
        String lastURL = "viewAllPurchaseOrder.xhtml";
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("lastURL", lastURL);
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("purchaseOrder", selectedPurchaseOrder);
        FacesContext.getCurrentInstance().getExternalContext().redirect("displayPurchaseOrder.xhtml");
    }

    public void confirmSalesOrder(SalesOrderEntity salesOrder) throws IOException {
        selectedPurchaseOrder = salesOrder;
        String lastURL = "viewAllPurchaseOrder.xhtml";
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("lastURL", lastURL);
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("purchaseOrder", selectedPurchaseOrder);
        FacesContext.getCurrentInstance().getExternalContext().redirect("confirmPurchaseOrder.xhtml");
    }
       public void amendPurchaseOrder(SalesOrderEntity salesOrder) throws IOException {
        selectedPurchaseOrder = salesOrder;
        String lastURL = "viewAllPurchaseOrder.xhtml";
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("lastURL", lastURL);
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("purchaseOrder", selectedPurchaseOrder);
        FacesContext.getCurrentInstance().getExternalContext().redirect("amendPurchaseOrder.xhtml");
    }

    public SalesOrderEntity getSelectedPurchaseOrder() {
        return selectedPurchaseOrder;
    }

    public void setSelectedPurchaseOrder(SalesOrderEntity selectedPurchaseOrder) {
        this.selectedPurchaseOrder = selectedPurchaseOrder;
    }

    public SalesmanEntity getEmployee() {
        return employee;
    }

    public void setEmployee(SalesmanEntity employee) {
        this.employee = employee;
    }

    public Boolean getRenderFlag() {
        return renderFlag;
    }

    public void setRenderFlag(Boolean renderFlag) {
        this.renderFlag = renderFlag;
    }
}
